/*
 * @(#)ContrastPalette.java	0.1 2003. 2. 14.
 * 
 * Copyleft 2002 Wonseok Shin Taeksoo Jung
 * Anyone can get benefits from this.
 */
package cs348a.color;

/**
 * A <code>ContrastPalette</code> defines a high contrast palette.
 * 
 * @version	0.1
 * @author		Wonseok Shin, Taeksoo Jung
 * @since		0.1
 */
public final class ContrastPalette extends BasicPalette {
	/** Limit of the first term */
	private static final int TERM_LIMIT1 = SIZE * 1 / 4;
	
	/** Limit of the second term */
	private static final int TERM_LIMIT2 = SIZE * 2 / 4;
	
	/** Limit of the third term */
	private static final int TERM_LIMIT3 = SIZE * 3 / 4;
	
	/** Singleton instance */
	public static final ContrastPalette INSTANCE = getInstance();

	/**
	 * Constructor for <code>ContrastPalette</code>.
	 * 
	 * @param reds array of red components
	 * @param greens array of green components
	 * @param blues array of blue components
	 */
	private ContrastPalette(byte[] reds, byte[] greens, byte[] blues) {
		super("Contrast", reds, greens, blues);
	}
	
	/**
	 * Returns the singleton instance.
	 * 
	 * @return the singleton instance
	 */
	private static ContrastPalette getInstance() {
		// Creates arrays of components.
		byte[] reds = new byte[SIZE];
		byte[] greens = new byte[SIZE];
		byte[] blues = new byte[SIZE];
		
		// Creates the first term of the components.
		for (int i = 0; i < TERM_LIMIT1; i++) {
			// Sets the red component.
			double f = 0;
			reds[i] = cutOff(f);

			// Sets the green component.
			f = i * SIZE / TERM_LIMIT1;
			greens[i] = cutOff(f);

			// Sets the blue component.
			f = SIZE;
			blues[i] = cutOff(f);		
		}

		// Creates the second term of the components.
		for (int i = TERM_LIMIT1; i < TERM_LIMIT2; i++) {
			// Sets the red component.
			double f = 0;
			reds[i] = cutOff(f);

			// Sets the green component.
			f = SIZE;
			greens[i] = cutOff(f);

			// Sets the blue component.
			f = -i * SIZE / (TERM_LIMIT2 - TERM_LIMIT1)
				+ TERM_LIMIT2 * SIZE / (TERM_LIMIT2 - TERM_LIMIT1);
			blues[i] = cutOff(f);
		}
		
		// Creates the third term of the components.
		for (int i = TERM_LIMIT2; i < TERM_LIMIT3; i++) {
			// Sets the red component.
			double f = i * SIZE / (TERM_LIMIT3 - TERM_LIMIT2) 
						- TERM_LIMIT2 * SIZE / (TERM_LIMIT3 - TERM_LIMIT2);
			reds[i] = cutOff(f); 

			// Sets the green component.
			f = SIZE;
			greens[i] = cutOff(f);

			// Sets the blue component.
			f = 0;
			blues[i] = cutOff(f);
		}

		// Forth term.
		for (int i = TERM_LIMIT3; i < SIZE; i++) {
			// Sets the red component.
			double f = SIZE;
			reds[i] = cutOff(f);

			// Sets the green component.
			f = -i * SIZE / (SIZE - TERM_LIMIT3)
				+ SIZE * SIZE / (SIZE - TERM_LIMIT3);
			greens[i] = cutOff(f);

			// Sets the blue component.
			f = 0;
			blues[i] = cutOff(f);
		}
		
		return new ContrastPalette(reds, greens, blues);
	}
}
